package com.baimawangzi.recovery.servlet.integral;

import com.baimawangzi.recovery.bean.Integral;
import com.baimawangzi.recovery.service.impl.IntegralServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Date;

@WebServlet("/integralupdate.do")
public class IntegralUpdateServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("in IntegralUpdateServlet");
        //解析url参数
        IntegralServiceImpl integralService = new IntegralServiceImpl();
        String sid =req.getParameter("id");
        String username=req.getParameter("username");
        String sintegral=req.getParameter("integral");
        java.util.Date date = new java.util.Date();
        //造对象
        Integral integral = new Integral(Integer.parseInt(sid), username, new Date(date.getTime()), Integer.parseInt(sintegral));

        int a = integralService.update(integral);
        if(a>0){//提示信息
            req.setAttribute("msg","修改积分成功");
        }
        else {
            req.setAttribute("msg","修改积分失败");
        }
        try {
            req.getRequestDispatcher("integrallist.do").forward(req,resp);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
